package org.crc.myvhrb.controller.system.basic;

import org.crc.myvhrb.model.Position;
import org.crc.myvhrb.model.RespBean;
import org.crc.myvhrb.service.PositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * CRC
 * 2021/8/6
 */
@RequestMapping("/system/basic/pos")
@RestController
public class PositionController {

    @Autowired
    PositionService positionService;

    /**
     *  获取全部职位数据
     * @return
     */
    @GetMapping("/")
    public List<Position> getAllPosition(){
        return positionService.getAllPosition();
    }

    @PostMapping("/")
    public RespBean insertSelective(@RequestBody Position position){
        if (positionService.insertSelective(position) == 1){
            return RespBean.success("添加成功");
        }
        return RespBean.error("添加失败");
    }
    @PutMapping("/")
    public RespBean updateByPrimaryKeySelective(@RequestBody Position position){
        if (positionService.updateByPrimaryKeySelective(position) == 1){
            return RespBean.success("更新成功");
        }
        return RespBean.error("更新失败");
    }

    @DeleteMapping("/{id}")
    public RespBean deleteByPrimaryKey(@PathVariable int id){
        if (positionService.deleteByPrimaryKey(id) == 1){
            return RespBean.success("删除成功");
        }
        return RespBean.error("删除失败");
    }


    @DeleteMapping("/")
    public RespBean deletePositionByIds(Integer[] ids){
        if (positionService.deletePositionByIds(ids) == ids.length){
            return RespBean.success("删除成功");
        }
        return RespBean.error("删除失败");
    }

}
